package cn.edu.zut.response;

import org.apache.commons.io.IOUtils;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author Davey chan
 */
//*响应字节数据：设置字 “节”数据的响应体
// */
@WebServlet("/resp4")
public class responseDemo4 extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1，读取文件
        FileInputStream fis = new FileInputStream("D:/Homework/web-page/vue网页作业/src/img/1.jpg");

//2,获取字节输出流
        ServletOutputStream os = response.getOutputStream();

//3，完成流的copy,采用工具来实现copy
        IOUtils.copy(fis,os);
//        关闭字节输入流，输出不需要
        fis.close();
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }


}
